import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:sinosheets/components/input/one_line_input_widget.dart';
import 'package:sinosheets/utils/theme/style_utils.dart';

import 'logic.dart';

class EstimatePage extends StatefulWidget {
  const EstimatePage({Key? key}) : super(key: key);

  @override
  State<EstimatePage> createState() => _EstimatePageState();
}

class _EstimatePageState extends State<EstimatePage> {
  final EstimateLogic logic = Get.put(EstimateLogic());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<EstimateLogic>(builder: (get) {
      return Scaffold(
        appBar: AppBar(
          title: Text('Estimate', style: TextStyle(fontSize: 22.r, fontWeight: FontWeight.bold, color: Colors.black)),
          elevation: 0,
          centerTitle: false,
        ),
        body: Column(
          children: [
            Expanded(
              child: Container(
                color: Colors.transparent,
                margin: EdgeInsets.symmetric(horizontal: 10.r, vertical: 16.r),
                child: CustomScrollView(
                  slivers: [
                    countrySelectWidget(),
                    weightInputWidget(),
                    lengthInputWidget(),
                    // productSelectWidget(),
                    operatorWidget(),
                  ],
                ),
              ),
            ),
          ],
        ),
      );
    });
  }

  /// 国家选择
  Widget countrySelectWidget() {
    return SliverToBoxAdapter(
      child: GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: logic.onCountryClick,
        child: Container(
          margin: EdgeInsets.only(bottom: 12.r),
          padding: EdgeInsets.symmetric(horizontal: 16.r),
          height: 51.r,
          decoration: BoxDecoration(
            color: ColorUtils.c_ffffff,
            borderRadius: BorderRadius.circular(8.r),
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Row(
                children: [
                  Text("*", style: StyleUtils.ts_fd3850_14_500),
                  Text("warehouse_delivery".tr, style: StyleUtils.ts_1f_14_500),
                ],
              ),
              Row(
                children: [
                  OneLineInputWidget(
                    width: 150.r,
                    controller: logic.countryController,
                    placeholder: "placeholder_select".tr,
                    placeholderStyle: StyleUtils.ts_99_14_400,
                    style: StyleUtils.ts_1f_14_500,
                    enabled: false,
                    textAlign: TextAlign.end,
                  ),
                  Icon(
                    Icons.chevron_right,
                    color: ColorUtils.c_999999,
                    size: 16,
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }

  /// 商品
  Widget productSelectWidget() {
    return SliverToBoxAdapter(
      child: GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: logic.onProductClick,
        child: Container(
          margin: EdgeInsets.only(bottom: 12.r),
          padding: EdgeInsets.symmetric(horizontal: 16.r),
          height: 51.r,
          decoration: BoxDecoration(
            color: ColorUtils.c_ffffff,
            borderRadius: BorderRadius.circular(8.r),
          ),
          child: Row(
            children: [
              Text("product_type".tr, style: StyleUtils.ts_1f_14_500),
              SizedBox(width: 10.r),
              Expanded(
                child: Text(
                  logic.isLimitSelect ? logic.selectLimitText : "placeholder_select".tr,
                  style: logic.isLimitSelect ? StyleUtils.ts_1f_14_500 : StyleUtils.ts_99_14_400,
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                  textAlign: TextAlign.end,
                ),
              ),
              SizedBox(width: 4.r),
              Icon(
                Icons.chevron_right,
                color: ColorUtils.c_999999,
                size: 16.r,
              ),
            ],
          ),
        ),
      ),
    );
  }

  /// 重量输入
  Widget weightInputWidget() {
    return SliverToBoxAdapter(
      child: Container(
        margin: EdgeInsets.only(bottom: 12.r),
        padding: EdgeInsets.symmetric(horizontal: 16.r),
        height: 51.r,
        decoration: BoxDecoration(
          color: ColorUtils.c_ffffff,
          borderRadius: BorderRadius.circular(8.r),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Row(
              children: [
                Text("*", style: StyleUtils.ts_fd3850_14_500),
                Text("${"actual_weight".tr}(g)", style: StyleUtils.ts_1f_14_500),
              ],
            ),
            OneLineInputWidget(
              width: 150.r,
              controller: logic.weightController,
              placeholder: "placeholder_weight".tr,
              placeholderStyle: StyleUtils.ts_99_14_400,
              style: StyleUtils.ts_1f_14_500,
              textAlign: TextAlign.end,
              keyboardType: TextInputType.numberWithOptions(decimal: true),
            ),
          ],
        ),
      ),
    );
  }

  /// 长宽高输入
  Widget lengthInputWidget() {
    return SliverToBoxAdapter(
      child: Container(
        margin: EdgeInsets.only(bottom: 12.r),
        padding: EdgeInsets.symmetric(horizontal: 16.r, vertical: 10.r),
        decoration: BoxDecoration(
          color: ColorUtils.c_ffffff,
          borderRadius: BorderRadius.circular(8.r),
        ),
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  children: [
                    Text("${"length".tr}(cm)", style: StyleUtils.ts_1f_14_500),
                  ],
                ),
                OneLineInputWidget(
                  controller: logic.lengthController,
                  placeholder: "placeholder_length".tr,
                  placeholderStyle: StyleUtils.ts_99_14_400,
                  style: StyleUtils.ts_1f_14_500,
                  textAlign: TextAlign.end,
                  margin: EdgeInsets.only(bottom: 10.r),
                  keyboardType: TextInputType.numberWithOptions(decimal: true),
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  children: [
                    Text("${"width".tr}(cm)", style: StyleUtils.ts_1f_14_500),
                  ],
                ),
                OneLineInputWidget(
                  controller: logic.widthController,
                  placeholder: "placeholder_width".tr,
                  placeholderStyle: StyleUtils.ts_99_14_400,
                  style: StyleUtils.ts_1f_14_500,
                  textAlign: TextAlign.end,
                  margin: EdgeInsets.only(bottom: 10.r),
                  keyboardType: TextInputType.numberWithOptions(decimal: true),
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  children: [
                    Text("${"height".tr}(cm)", style: StyleUtils.ts_1f_14_500),
                  ],
                ),
                OneLineInputWidget(
                  controller: logic.heightController,
                  placeholder: "placeholder_height".tr,
                  placeholderStyle: StyleUtils.ts_99_14_400,
                  style: StyleUtils.ts_1f_14_500,
                  textAlign: TextAlign.end,
                  keyboardType: TextInputType.numberWithOptions(decimal: true),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }

  /// 底部操作区域
  Widget operatorWidget() {
    return SliverToBoxAdapter(
      child: GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: logic.onEstimateClick,
        child: Container(
          margin: EdgeInsets.only(top: 12.r),
          height: 40.r,
          decoration: BoxDecoration(
            color: ColorUtils.themeColor,
            borderRadius: BorderRadius.circular(20.r),
          ),
          child: Center(
            child: Text(
              "check".tr,
              style: StyleUtils.ts_ff_16_500,
            ),
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<EstimateLogic>();
    super.dispose();
  }
}
